	/**
	 * Assigns random prefixes to all the elements of the xml document passed
	 * @param xmldoc - XML document whose prefixes are to be resolved
	 */
	function resolvePrefixes(xmldoc){
		var prefixStack = [];
		var ns2PrefixMap = {};
		var xmlstring = cordys.getXML(xmldoc);
		var nodeArray = xmlstring.split("<");
		var nodeCount = nodeArray.length;
		for (var i = 1; i < nodeCount; i++) {
			var currentNode = nodeArray[i];
			var parsedNode = nodeArray[i].match(/^(\/?)(([^\s:]+):)?(.*?)(?:(xmlns|xmlns:\3)(="(.*?)")(.*?))?(\/?)(>.*)/);
			var stackOperation = parsedNode[1] == "/" ? "pop" : "push";
			var currentPrefix = parsedNode[3];
			var xmlns = parsedNode[7];
			if (currentPrefix && xmlns && !ns2PrefixMap[xmlns]) {
				ns2PrefixMap[xmlns] = currentPrefix;
			} else if (!currentPrefix && xmlns) {
				var currentPrefix = ns2PrefixMap[xmlns] || generatePrefix();
				ns2PrefixMap[xmlns] = currentPrefix;
				nodeArray[i] = currentPrefix + ":" + parsedNode[4] + parsedNode[5] + ":" + currentPrefix + parsedNode[6] + parsedNode[8] + parsedNode[9] + parsedNode[10];
			} else if (!currentPrefix && !xmlns) {
				currentPrefix = prefixStack[prefixStack.length -1];
				nodeArray[i] = parsedNode[1] + currentPrefix + ":" + parsedNode[4] + parsedNode[9] + parsedNode[10];						
			}
			parsedNode[9] != '/' && prefixStack[stackOperation](currentPrefix);
		}
		var xmldoc = cordys.loadXMLDocument(nodeArray.join("<"));
		return cordys.selectXMLNode(xmldoc, ".//*");
	}
	
	/**
	 * Returns a random 5 character string
	 */
	function generatePrefix() {
		var sampleText = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890".split("");
		var prefix = "";
		for(var i = 0; i < 2; i++)
			prefix += sampleText[Math.floor(Math.random() * 52)];
		for(var i = 0; i < 3; i++)
			prefix += sampleText[Math.floor(Math.random() * 10) + 52];			
		return prefix;
	}			
